define(
    function (require) {
        var BaseListModel = require('common/ListModel');
        var Data = require('./Data');
        var datasource = require('er/datasource');
        var name;
        var page;
        var phone;
        var zname;
        var cname;


        function ReportListModel() {
            BaseListModel.apply(this, arguments);
            var entityName = this.getUrlType();
            this.addData(new Data(entityName));
            if (arguments.length > 0) {
                phone = arguments[0].phone;
                zname = arguments[0].zname;
                cname = arguments[0].cname;
                page = arguments[0].page;
                if(page === '' || typeof(page) === 'undefined'){
                    page = 1;
                }


                if (phone !== '' && typeof(phone) !== 'undefined' || zname !== '' && typeof(zname) !== 'undefined'|| cname !== '' && typeof(cname) !== 'undefined' ) {
                    this.datasource = {
                        list: function (model) {
                            return model.data().searchByPhone(phone,zname,cname).then(
                                function (data) {
                                    return data;
                                }
                            );
                        }
                    };
                } else {
                    this.datasource = {
                        list: function (model) {
                            return model.data().search(page).then(
                                function (data) {
                                    return data;
                                }
                            );
                        }
                    };
                }
            }else{
                this.datasource = {
                    list: function (model) {
                        return model.data().search().then(
                            function (data) {
                                return data;
                            }
                        );
                    }
                };
            }
        }

        ReportListModel.prototype.prepare = function() {
            var list = this.get('list');
            if(typeof(list.pageCount) === 'undefined'){
                this.set('totalCount', 0);
                this.set('pageCount', 1);
            }else if(list.pageCount === 0){
                this.set('totalCount', 0);
                this.set('pageCount', 1);
            } else{
                var pageCount =  Math.ceil(list.pageCount/ 10);
                this.set('totalCount', list.pageCount);
                this.set('pageCount', pageCount );
            }
            this.set('page', page );
            this.set('phone',phone);
            this.set('zname',zname);
            this.set('cname',cname);
            this.set('list', list);
        };

        ReportListModel.prototype.find = function(isbn) {
            var list = this.get('list');
            return null;
        };

        require('er/util').inherits(ReportListModel, BaseListModel);
        return ReportListModel;
    }
);
